package com.apes.scm.voucher.model;

import com.apes.fico.engine.annotation.AccountingEngineOneToOne;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.account.model.InventoryMode;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @Title: VoucherFinExtension
 * @Description: 业务凭证财务拓展表（用于结转财务凭证使用)
 * @author: ZhengZeXian
 * @create: 2022/6/6 16:21
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
//@Accessors(chain = true) //禁止使用链式调用
@EntityListeners(DefaultPersistListener.class)
@Table(name = VoucherFinExtension.CONST_TABLE_NAME)
public class VoucherFinExtension extends Model {

    public static final String CONST_TABLE_NAME = "acc_voucher_fin_extension";

    @Id
    @Column(name = "id", length = 32)
    @Comment("凭证单号")
    private String id;

    @AccountingEngineOneToOne
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "voucher_id", referencedColumnName = "id")
    @Comment("业务凭证")
    private Voucher voucher;

    @Column(name = "classification", length = 30)
    @Comment("凭证分类[01:直供;02:油漆商品;03:经销带安;04:代销带安;05:工单内协;06:整单内协;07:服务商品;08:委托定损;09:委托定损[定损方];" +
            "CROSS_IC:异业销售;CROSS_IC_CROSS_RETURN:异业退货[平台];CROSS_IC_RETURN:异业退货;E_MAINTAIN:e服务;INSURANCE:卖单定损]")
    private String classification;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("业务公司编码")
    private PartyRole company;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id", nullable = false)
    @Comment("部门编码")
    private Dept dept;

    @Column(name = "voucher_type", length = 30, nullable = false)
    @Comment("凭证类型")
    private String voucherType;

    /**
     * 库存方式
     * 1. 适用于：经销
     * IM_OWN: 自有
     * 2. 适用于：代销、联营
     * IM_CONSIGN: 寄售
     */
    @States(name = "库存方式", values = {
            @State(id = InventoryMode.IM_OWN, name = "自有"),
            @State(id = InventoryMode.IM_CONSIGN, name = "寄售")})
    @Column(name = "inventory_mode", nullable = false, length = 20)
    private String inventoryMode; //库存方式

    @Column(name = "supply_chain_management_fee", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("供应链管理费")
    private double supplyChainManagementFee = 0;

    @Column(name = "platform_management_fee", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("平台管理费")
    private double platformManagementFee = 0;

    @Column(name = "platform_service_fee_reduced", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("平台服务费减免额")
    private double platformServiceFeeReduced = 0;

    @Column(name = "loss_Quotation_fee", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("定损信息费合计")
    private double lossQuotationFee = 0;

    @Column(name = "platform_internal_reduced", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("内部销售服务费减免额度")
    private double platformInternalReduced = 0;

    @Column(name = "base_platform_management_fee", columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("定损基地平台服务费")
    private double basePlatformManagementFee = 0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "platform_company_id", referencedColumnName = "id")
    @Comment("平台公司编码")
    private PartyRole platformCompany;


}
